/**
 * create by akon
 * date: 2016年12月3日22:31:15
 * 后台javascript相关文件
 */
jQuery(document).ready(function() {

    $('.page-container form').submit(function(){
        var username = $(this).find('.username').val();
        var password = $(this).find('.password').val();
        if(username == '') {
            $(this).find('.error').fadeOut('fast', function(){
                $(this).css('top', '27px');
            });
            $(this).find('.error').fadeIn('fast', function(){
                $(this).parent().find('.username').focus();
            });
            return false;
        }
        if(password == '') {
            $(this).find('.error').fadeOut('fast', function(){
                $(this).css('top', '96px');
            });
            $(this).find('.error').fadeIn('fast', function(){
                $(this).parent().find('.password').focus();
            });
            return false;
        }
    });

    $('.page-container form .username, .page-container form .password').keyup(function(){
        $(this).parent().find('.error').fadeOut('fast');
    });


    /**后台登录验证**/
    $(".admin_form").submit(function(){
        var username = $('.username').val();
        var password = $('.password').val();
        var verfiy   = $('.verify').val();
        //判断表单数据是否为空
        isEmpty(username,password,verfiy);
        var info = {
            username : username,
            password : encryptPass(password),      //密码使用encript加密
            verfiy   : verfiy,
        }
        $.ajax({
            url: _system.module + '/Admin/login',
            type: 'post',
            data: {info : info},
            success: function(res){
                if(res.status == 0){
                    layerMsg(res.msg);
                }else{
                    window.location.href = res.url;
                }
            }
        })
    })
    function isEmpty(username,password,verfiy){
        if(Trim(username) == '' || Trim(username) == 'undefined'){
            layerMsg("用户名不能为空");
            return;
        }else if(Trim(password) == '' || Trim(password) == 'undefined'){
            layerMsg("密码不能为空");
            return;
        }else if(Trim(verfiy) == '' || Trim(verfiy) == 'undefined'){
            layerMsg("验证码不能为空");
            return;
        }
    }

});

/**点击刷新验证码**/
function freshVerify(){
    $('#imgVerify').attr('src','/index.php?m=Manager&c=Admin&a=vertify&r=' + Math.floor(Math.random()*100));
}
/**判断表单数据是否为空**/
function isEmpty(content,msg){
    if(Trim(content) == '' || Trim(content) == 'undefined'){
        layerMsg(msg);
        return;
    }
}
